from flask import Blueprint, request, jsonify
from app import db
from app.models.exponent import Exponent

exponents_bp = Blueprint('exponent', __name__, url_prefix='/exponent')

# 获取所有exponent
@exponents_bp.route('', methods=['GET'])
def get_exponents():
    try:
        cid = request.args.get('cid')
        pid = request.args.get('pid')
        exponents = Exponent.query.filter_by(cid=cid,pid=pid).all()
        exponents_data = [exponent.to_dict() for exponent in exponents]
        
        # 检查是否有数据
        if not exponents_data:
            return jsonify({
                'message': '数据为空'
            }), 200
        
        return jsonify({
            "cid": exponents_data[0]['cid'],
            "created_at": exponents_data[0]['created_at'],
            "dopen": exponents_data[0]['dopen'],
            "dopen2": exponents_data[0]['dopen2'],
            "mteam": exponents_data[0]['mteam'],
            "mteam2": exponents_data[0]['mteam2'],
            "pid": exponents_data[0]['pid'],
            "vteam": exponents_data[0]['vteam'],
            "vteam2": exponents_data[0]['vteam2']
        }), 200
    except Exception as e:
        return jsonify({
            'message': '数据为空'
        }), 500